package com.book.controller;

import com.book.dto.UserPage;
import com.book.entity.User;
import com.book.service.UserService;
import com.book.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yicheng
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 用户自己修改除密码外的四个选项
     * @param code
     * @param user
     * @return
     */
    @PostMapping("/editSelf")
    public ResponseResult editOwn(@RequestParam String code, @RequestBody User user){
        return userService.editSelf(code,user);
    }

    @GetMapping("/getSelf")
    public ResponseResult getOwn(@RequestParam String userId){
        return userService.getSelf(userId);
    }

    @GetMapping("/editPwd")
    public ResponseResult editPassword(@RequestParam String userId,@RequestParam String code,@RequestParam String email,@RequestParam String pwd){
        return userService.editPwd(userId,code,email,pwd);
    }

    @PostMapping("/getList")
    public ResponseResult getList(@RequestBody UserPage userPage){
        return userService.getList(userPage);
    }

    @PostMapping("/updateStatus")
    public ResponseResult updateStatus(@RequestBody User user){
        return userService.updateStatus(user);
    }

    @PostMapping("/resetPwd")
    public ResponseResult resetPwd(@RequestBody User user){
        return userService.resetPwd(user);
    }

    @GetMapping("/deleteUser")
    public ResponseResult deleteUser(@RequestParam String id){
        return userService.deleteUser(id);
    }
}
